home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: undergrad.math.uwaterloo.ca!clgonsal
- From: clgonsal@undergrad.math.uwaterloo.ca (Carl Laurence Gonsalves)
- Subject: Re: writing to .exe file
- Sender: news@undergrad.math.uwaterloo.ca (news spool owner)
- Message-ID: <Dn6pHy.DoI@undergrad.math.uwaterloo.ca>
- Date: Thu, 22 Feb 1996 15:53:58 GMT
- References: <4g961o$gdr@ultra.sonic.net> <4gbkak$d42@news-f.iadfw.net>
- Nntp-Posting-Host: cayley.uwaterloo.ca
- Organization: University of Waterloo
-
- In article <4gbkak$d42@news-f.iadfw.net>, bob <alpet@airmail.net> wrote:
- >Ted Rollheiser <trollhei@sonic.net> wrote:
- >
- >>I would like to save data ( a string ) from one run of a (dos) program
- >>to the next by writing it to the .exe file. does this sound doable?
- >
- >Sure, programs do it all the time. Important part is to be sure space
- >is allocated for your string, and that you have some marker to find
- >the string. Do something like this:
- >
- >struct blah
- >{
- > char marker[10]="!@#$%%$#@!";
- > char comment[80];
- >}
- >
- >This allocats a structure in your .exe file. When your program runs,
- >open the file (your .exe) in binary mode and scan for the marker.
- >When you find it, you know the next 80 bytes are yours to play with.
- >Modify to your hearts content. A side note is a good idea to *not*
- >stop at the first occurence of your marker. It might be a fluke and
- >some real code in your program may dup this marker if the you find is
- >not yours, overwriting the next 80 bytes could be real bad. So go
- >ahead and scan the whole file to be sure it doesn't occur again.
-
- A simpler approach might be to write a separate program that appends your
- data to the end of the executable after it's been compiled (and linked).
- You can then safely assume that the x number of bytes on the end of the
- executable are your data.
-
- fseek( fp, -sizeof(myData), SEEK_END );
- fread( &myData, sizeof(myData), 1, fp );
-
- --
- Carl Laurence Gonsalves - clgonsal@undergrad.math.uwaterloo.ca
- Computer Science, University of Waterloo
- http://www.undergrad.math.uwaterloo.ca/~clgonsal/
- http://www.csclub.uwaterloo.ca/~clgonsal/
-